#include "room.h"
#include <stdio.h>
void printRoomPeople(struct room *room);
void printRoom(void);
int main(void){
	roomInit();
	struct person *p1, *p2;
	p1=joinNewPerson(1,"황세윤");
	printf("%s가 들어옴\n",p1->name);
	p2=joinNewPerson(2,"이동석");
	printf("%s가 들어옴\n",p2->name);
	printRoomPeople(&lobby);
	struct room *r1=makeNewRoom(p1,"방1");
	printf("방 \"%s\"가 생성, 방장은 %s\n",r1->name,p1->name);
	printRoom();
	printRoomPeople(&lobby);
	printRoomPeople(r1);
	enterRoomPerson(r1,p2);
	printf("방 \"%s\"에 %s가 입장\n",r1->name,p2->name);
	printRoomPeople(&lobby);
	printRoomPeople(r1);
	enterRoomPerson(&lobby,p1);
	printf("%s가 로비로 이동\n",p1->name);
	printRoom();
	printRoomPeople(&lobby);
	struct person *p3=joinNewPerson(3,"임호용");
	printf("%s가 들어옴\n",p3->name);
	r1=makeNewRoom(p3,"방2");
	printf("방 \"%s\"가 생성, 방장 : %s\n",r1->name,p3->name);
	enterRoomPerson(r1,p1);
	printf("방 \"%s\"에 %s가 입장\n",r1->name,p1->name);
	enterRoomPerson(r1,p2);
	printf("방 \"%s\"에 %s가 입장\n",r1->name,p2->name);
	printRoom();
	printRoomPeople(&lobby);
	printRoomPeople(r1);
	struct room *tr=findRoom(1);
	if(tr!=NULL)
		printf("%s방 검색\n",tr->name);
	printf("%s가 접속 종료\n",p3->name);
	exitPerson(p3);
	printRoom();
	printRoomPeople(&lobby);
	struct person *p=findPerson(3);
	if(p!=NULL)
		printf("%s는 현재 방 \"%s\"에 있음\n",p->name,p->curRoom->name);
	printf("%s가 접속 종료\n",p2->name);
	exitPerson(p2);
	printf("%s가 접속 종료\n",p1->name);
	exitPerson(p1);
	return 0;	
}
void printRoomPeople(struct room *room){
	printf("방 \"%s\"의 인원 \n",room->name);
	struct personList *t=room->list;
	while(t!=NULL){
		printf("%d %s\n",t->person->fd,t->person->name);
		t=t->next;
	}
	printf("=============================\n");
}
void printRoom(void)
{
	printf("==방 리스트 ==\n");
	struct room *t=roomList;
	while(t!=NULL){
		printf("%s\n",t->name);
		t=t->next;
	}
	printf("=============================\n");
}
